//
//  SFCustomButton.m
//  text
//
//  Created by apple on 2019/4/10.
//  Copyright © 2019 apple. All rights reserved.
//  自定义button

#import "SFCustomButton.h"
#import "Masonry.h"
#import <oneCommonLib/UIView+Extension.h>
#import "HeaderConfig.h"

@interface SFCustomButton ()
@property(nonatomic, assign) CGFloat imageWidth;
@end

@implementation SFCustomButton

- (instancetype)initWithFrame:(CGRect)frame imageWidth:(CGFloat)width {
    self = [super initWithFrame:frame];
    if (self) {
        _imageWidth = width;
        [self createSubviews];
        //        kViewBorderRadius(self.buttonImageView, 16, 0, [UIColor whiteColor]);
    }
    return self;
}
- (void)createSubviews {
    self.buttonImageView = [[UIImageView alloc] init];
    [self addSubview:self.buttonImageView];

    self.buttonLB = [[UILabel alloc] init];
    self.buttonLB.textColor = KUIColorFromRGB(0x333333);
    self.buttonLB.font = KFont_B(12);
    [self addSubview:self.buttonLB];
}
- (void)layoutSubviews {
    [self.buttonImageView mas_makeConstraints:^(MASConstraintMaker *make) {
      make.centerX.equalTo(self.mas_centerX);
      make.top.equalTo(self.mas_top).mas_offset(0);
      make.width.height.mas_offset(self.imageWidth > 0 ? self.imageWidth : 42);
    }];

    [self.buttonLB mas_makeConstraints:^(MASConstraintMaker *make) {
      make.centerX.equalTo(self.mas_centerX);
      make.top.equalTo(self.buttonImageView.mas_bottom).mas_offset(3);
    }];
}
@end

@implementation SFChargeButton
- (void)awakeFromNib {
    [super awakeFromNib];
    [self createSubviews];
}
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubviews];
    }
    return self;
}
- (void)createSubviews {
    self.backImageView = [UIImageView createImageViewImageName:@"" superUIView:self];

    self.vipImageView = [UIImageView createImageViewImageName:@"标签" superUIView:self];

    self.vipDutionLB = [UILabel creatLabelWithTitle:@"一天会员" textColor:KUIColorFromRGB(0xffffffff) textFont:KFont_B(8)];
    self.vipDutionLB.textAlignment = NSTextAlignmentCenter;

    self.priceLB = [UILabel creatLabelWithTitle:@"30.00元" textColor:KUIColorFromRGB(0xff3030) textFont:KFont_B(16)];
    self.priceLB.textAlignment = NSTextAlignmentCenter;

    self.dutionLB = [UILabel creatLabelWithTitle:@"三个月无限观看" textColor:KUIColorFromRGB(0x333333) textFont:KFont_B(12)];
    self.dutionLB.textAlignment = NSTextAlignmentCenter;

    self.introduceLB = [UILabel creatLabelWithTitle:@"漫画直播免费看" textColor:KUIColorFromRGB(0x8A8A8A) textFont:KFont_B(10)];
    self.introduceLB.textAlignment = NSTextAlignmentCenter;

    [self addSubview:self.vipDutionLB];
    [self addSubview:self.priceLB];
    [self addSubview:self.dutionLB];
    [self addSubview:self.introduceLB];
}
- (void)layoutSubviews {
    [self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
      make.edges.equalTo(self);
    }];
    [self.vipImageView mas_makeConstraints:^(MASConstraintMaker *make) {
      make.left.equalTo(self.mas_left).mas_offset(-3);
      make.top.equalTo(self.mas_top).mas_offset(2);
      make.width.mas_offset(52);
      make.height.mas_offset(20);
    }];

    [self.vipDutionLB mas_makeConstraints:^(MASConstraintMaker *make) {
      make.left.equalTo(self.mas_left).mas_offset(3);
      make.centerY.equalTo(self.vipImageView.mas_centerY);
    }];

    [self.priceLB mas_makeConstraints:^(MASConstraintMaker *make) {
      make.top.equalTo(self.mas_top).mas_offset(13);
      make.centerX.equalTo(self.mas_centerX);
    }];

    [self.dutionLB mas_makeConstraints:^(MASConstraintMaker *make) {
      make.top.equalTo(self.priceLB.mas_bottom).mas_offset(2);
      make.centerX.equalTo(self.mas_centerX);
      make.left.equalTo(self.mas_left).mas_offset(15);
      make.right.equalTo(self.mas_right).mas_offset(-15);
    }];
    [self.introduceLB mas_makeConstraints:^(MASConstraintMaker *make) {
      make.top.equalTo(self.dutionLB.mas_bottom).mas_offset(2);
      make.centerX.equalTo(self.mas_centerX);
      make.left.equalTo(self.mas_left).mas_offset(15);
      make.right.equalTo(self.mas_right).mas_offset(-15);
    }];
}

@end
